package com.beimi.game.module;

import com.next.core.util.RandomUtil;

public class GameCardModule {
	private int numCard;

	private int[] cards;

	private int numPop;

	public GameCardModule() {
	}
	
	public void initDizhu() {
		for (int i = 0; i < numCard; i++) {
			cards[i] = i;
		}

		RandomUtil.shuffleArray(cards);
	}

	public void initMajiong() {
		numCard = 27 * 4;
		cards = new int[numCard];
		
		// 筒 (0 ~ 8 表示筒子
		int index = 0;
		for (int i = 0; i < 9; ++i) {
			for (int c = 0; c < 4; ++c) {
				cards[index] = i;
				index++;
			}
		}

		// 条 9 ~ 17表示条子
		for (int i = 9; i < 18; ++i) {
			for (int c = 0; c < 4; ++c) {
				cards[index] = i;
				index++;
			}
		}

		// 万
		// 条 18 ~ 26表示万
		for (int i = 18; i < 27; ++i) {
			for (int c = 0; c < 4; ++c) {
				cards[index] = i;
				index++;
			}
		}
		
		RandomUtil.shuffleArray(cards);
	}

	public boolean hasPai() {
		return numPop > numCard;
	}
	
	
	public int pop() {
		return cards[numPop++];
	}
}
